﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using XamlingCore.SL.Controls.ControlStyle.Interfaces;

namespace XamlingCore.SL.Controls.ControlStyle
{
    public abstract class StyleSelectorBase : IStyleSelector
    {
        private string defaultTemplate;

        public virtual Style SelectStyle(object content)
        {
            if (content != null)
            {
                if (typeCache.ContainsKey(content.GetType()))
                {
                    return Application.Current.Resources[typeCache[content.GetType()]] as Style;
                }
            }

            if (!string.IsNullOrEmpty(defaultTemplate))
            {
                return Application.Current.Resources[defaultTemplate] as Style;
            }

            return null;
        }

        Dictionary<Type, string> typeCache = new Dictionary<Type, string>();

        protected void RegisterType<T>(string templateName)
        {
            typeCache.Add(typeof(T), templateName);
        }

        protected void RegisterDefault(string templateName)
        {
            defaultTemplate = templateName;
        }
    }
}
